﻿using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.Phone.Controls.Maps;
using System.Net.NetworkInformation;

namespace GlobalRadar.Class
{
    class Support
    {
        public void GetAllPushpinGroupMe(MapDraw myMap,int UserID)
        {
            if (NetworkInterface.GetIsNetworkAvailable() == false) return;

            try
            {
                mySQLService.RadarServicePortTypeClient client = new mySQLService.RadarServicePortTypeClient();

                client.GetALlLocationInmyGroupCompleted += (s, args) =>
                {
                    if (args == null) return;

                    if (args.Result == null) return;

                    var tabledata = Json.ParseTable(args.Result);

                    myMap.ClearTrackTemp();

                    foreach (List<object> row in tabledata)
                    {
                        if (row.Count > 2)
                        {
                            Pushpin item = new Pushpin();
                            item.Content = row[0].ToString();
                            item.Location = new GeoCoordinate(double.Parse(row[1].ToString()), double.Parse(row[2].ToString()));
                            myMap.AddTrack(item);

                        }
                    }
                    myMap.ShowAllTrack();
                };
                client.GetALlLocationInmyGroupAsync(UserID);
            }
            catch (Exception ex)
            {
            }
        }
    }
    public class PushpinModel
    {
       public GeoCoordinate Location { get; set; }
    }
}
